import requests
class getRegionCode:
    def getRegionCode(self):
        are={
                # "520300": "遵义市",
                "52033010": "习水县回龙镇",
                # "520303": "汇川区",
                # "520321": "播州区",
                # "520322": "桐梓县",
                # "520323": "绥阳县",
                # "520324": "正安县",
                #"520325": "道真县",
                #"520326": "务川县",
                #"520327": "凤冈县",
                #"520328": "湄潭县",
                #"520329": "余庆县",
                 #"520330": "习水县",
                #"520381": "赤水市",
                # "520382": "仁怀市",
                # "520383": "新浦",
        }
        cookies = {
            'JSESSIONID': '57A6E030D83A9F1AB30DC9DC2DF3A153',
            'tempTokenKey': 'eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiLnhormr4UiLCJhdWQiOiI5RTEwNTlDOTMzNUQ0QzdDQjhEQzc0MDBEMDNBRUNGQiIsInNlcnZlciI6bnVsbCwicm9sZSI6IlJPTEVfQVJFQSxST0xFX1dJTkRPVyIsImlzSW5pdGlhbFBhc3N3b3JkIjoiMCIsInJlZ2lvbk5hbWUiOiLotLXlt57nnIEiLCJpbmR1c3RyeSI6bnVsbCwiYXBwQ29kZSI6ImRnb3YtcG9ydGFsIiwib3JnYW5OYW1lIjoi5LqR5LiK6LS15beeIiwicmVnaW9uQ29kZSI6IjUyMDAwMCIsImluZHVzdHJ5TGlzdCI6bnVsbCwib3JnYW5Db2RlIjoiNTIwMDAyIiwiZXhwaXJhdGlvblRpbWUiOjUsImdyYWRlIjoiMiIsInN0YXR1cyI6IjEiLCJpc3MiOiJpbnNwdXIiLCJpYXQiOjE3MTYyNTQzNTMsImV4cCI6MTcxNjI4MzE1M30.lw7BT-eB7X_WwO5aDXy_sZqMhSNlRCVrPyfjVsZSDxXuZwqFu2t7qAu1qFdm7zCHyvYKnO0MLYEAVGVqtthbfQ',
            'userInfoKey': '{^%^22role^%^22:^%^22ROLE_AREA^%^2CROLE_WINDOW^%^22^%^2C^%^22isInitialPassword^%^22:^%^220^%^22^%^2C^%^22regionName^%^22:^%^22^%^E8^%^B4^%^B5^%^E5^%^B7^%^9E^%^E7^%^9C^%^81^%^22^%^2C^%^22appCode^%^22:^%^22dgov-portal^%^22^%^2C^%^22organName^%^22:^%^22^%^E4^%^BA^%^91^%^E4^%^B8^%^8A^%^E8^%^B4^%^B5^%^E5^%^B7^%^9E^%^22^%^2C^%^22regionCode^%^22:^%^22520000^%^22^%^2C^%^22phone^%^22:^%^22384d53fa06a4844cfd54260b048c33e9^%^22^%^2C^%^22organCode^%^22:^%^22520002^%^22^%^2C^%^22expirationTime^%^22:5^%^2C^%^22name^%^22:^%^221342b48e6f8f39ea7ba36accc05b61a8^%^22^%^2C^%^22id^%^22:^%^229E1059C9335D4C7CB8DC7400D03AECFB^%^22^%^2C^%^22email^%^22:^%^22aa67c9bf293c42e9144476195b550c0f^%^22^%^2C^%^22username^%^22:^%^2247d57692a252657367001b6a2ff35333^%^22^%^2C^%^22status^%^22:^%^221^%^22^%^2C^%^22isWeakPwd^%^22:^%^220^%^22}',
            'pwdState': 'true',
            'inspurRoleKey': 'ROLE_AREA',
            'ASP.NET_SessionId': 'yhsbvlnz0n4biq55e0zmfr55',
            'windowId': '0B7CA12E92004E0ABCA9EB88F0A792E4',
            'wyhtml': '/zhslzy/_18f99f2f0eb33e9_1716274786539',
            'wyhijack': '/zhslzy/static/js/viewer.js_1716274787684',
            'James_cookie_sYQDUGqqzHtheme': 'custom',
            'webfinal.session.errorCount': '0',
        }

        headers = {
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:126.0) Gecko/20100101 Firefox/126.0',
            'Accept': 'application/json, text/javascript, */*; q=0.01',
            'Accept-Language': 'zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2',
            # 'Accept-Encoding': 'gzip, deflate',
            'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
            'X-Requested-With': 'XMLHttpRequest',
            'Origin': 'http://59.215.206.188',
            'Connection': 'keep-alive',
            'Referer': 'http://59.215.206.188/bsp/bsp/organ/region/index?v=1716275719134',
            # 'Cookie': 'JSESSIONID=BA2CF8734856578D8EE8BBCF2756A404; tempTokenKey=eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiLnhormr4UiLCJhdWQiOiI5RTEwNTlDOTMzNUQ0QzdDQjhEQzc0MDBEMDNBRUNGQiIsInNlcnZlciI6bnVsbCwicm9sZSI6IlJPTEVfQVJFQSxST0xFX1dJTkRPVyIsImlzSW5pdGlhbFBhc3N3b3JkIjoiMCIsInJlZ2lvbk5hbWUiOiLotLXlt57nnIEiLCJpbmR1c3RyeSI6bnVsbCwiYXBwQ29kZSI6ImRnb3YtcG9ydGFsIiwib3JnYW5OYW1lIjoi5LqR5LiK6LS15beeIiwicmVnaW9uQ29kZSI6IjUyMDAwMCIsImluZHVzdHJ5TGlzdCI6bnVsbCwib3JnYW5Db2RlIjoiNTIwMDAyIiwiZXhwaXJhdGlvblRpbWUiOjUsImdyYWRlIjoiMiIsInN0YXR1cyI6IjEiLCJpc3MiOiJpbnNwdXIiLCJpYXQiOjE3MTYyNTQzNTMsImV4cCI6MTcxNjI4MzE1M30.lw7BT-eB7X_WwO5aDXy_sZqMhSNlRCVrPyfjVsZSDxXuZwqFu2t7qAu1qFdm7zCHyvYKnO0MLYEAVGVqtthbfQ; userInfoKey={^%^22role^%^22:^%^22ROLE_AREA^%^2CROLE_WINDOW^%^22^%^2C^%^22isInitialPassword^%^22:^%^220^%^22^%^2C^%^22regionName^%^22:^%^22^%^E8^%^B4^%^B5^%^E5^%^B7^%^9E^%^E7^%^9C^%^81^%^22^%^2C^%^22appCode^%^22:^%^22dgov-portal^%^22^%^2C^%^22organName^%^22:^%^22^%^E4^%^BA^%^91^%^E4^%^B8^%^8A^%^E8^%^B4^%^B5^%^E5^%^B7^%^9E^%^22^%^2C^%^22regionCode^%^22:^%^22520000^%^22^%^2C^%^22phone^%^22:^%^22384d53fa06a4844cfd54260b048c33e9^%^22^%^2C^%^22organCode^%^22:^%^22520002^%^22^%^2C^%^22expirationTime^%^22:5^%^2C^%^22name^%^22:^%^221342b48e6f8f39ea7ba36accc05b61a8^%^22^%^2C^%^22id^%^22:^%^229E1059C9335D4C7CB8DC7400D03AECFB^%^22^%^2C^%^22email^%^22:^%^22aa67c9bf293c42e9144476195b550c0f^%^22^%^2C^%^22username^%^22:^%^2247d57692a252657367001b6a2ff35333^%^22^%^2C^%^22status^%^22:^%^221^%^22^%^2C^%^22isWeakPwd^%^22:^%^220^%^22}; pwdState=true; inspurRoleKey=ROLE_AREA; ASP.NET_SessionId=yhsbvlnz0n4biq55e0zmfr55; windowId=0B7CA12E92004E0ABCA9EB88F0A792E4; wyhtml=/zhslzy/_18f99f2f0eb33e9_1716274786539; wyhijack=/zhslzy/static/js/viewer.js_1716274787684; James_cookie_sYQDUGqqzHtheme=custom; webfinal.session.errorCount=0',
        }

        code = []
        for k,v in are.items():

            data = '_search=true&nd=1716275736003&rows=1000&page=1&sidx=code^%^2Csort_order&sord=asc&region_name=&code={}&name=&grade='.format(k)

            response = requests.post('http://59.215.206.188/bsp/bsp/organ/region/query', cookies=cookies, headers=headers, data=data).json()
            for i in response['rows']:
            #     code.append(i['cell']['CODE'])
            # codes.append(code)
            # print(codes)
            #     print(i['cell']['CODE'])
                code.append(i['cell']['CODE'])

        return code
getRegionCode().getRegionCode()
